package com.yang.file.config;

import com.yang.file.service.impl.MinIOFileStorageService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Billyang
 * @date 2024/9/23 17:16
 */
@Configuration
@EnableConfigurationProperties({MinIOConfigProperties.class})
@ConditionalOnMissingBean(MinIOFileStorageService.class)
public class FileStorageAutoConfiguration {

    @Bean
    @ConditionalOnProperty(prefix = "file-storage", name = "active", havingValue = "minio")
    public MinIOFileStorageService minIOFileStorageService(MinIOConfigProperties properties) {
        return new MinIOFileStorageService(properties.getAccessKey(), properties.getSecretKey(), properties.getEndpoint(),
                properties.getBucket(), properties.getReadPath());
    }
}
